﻿using OpenTK.Math;
using System.Runtime.InteropServices;

namespace Rekx.Graphics
{
    /// <summary>
    /// A BufferObject containing vertex coordinates
    /// </summary>
    public class VertexBuffer : Rekx.Graphics.BufferObject
    {
        /// <summary>
        /// Creates a new VertexBuffer from the given verticies
        /// </summary>
        /// <param name="vertices">Array of verticies to write to vram</param>       
        public VertexBuffer(Vector3[] vertices) : base(OpenTK.Graphics.BufferTarget.ArrayBuffer)
        {
            Insert(vertices.Length * OpenTK.Math.Vector3.SizeInBytes, vertices);
        }        
    }

    /// <summary>
    /// A BufferObject containing indices for a VertexBuffer
    /// </summary>
    public class IndexBuffer : Rekx.Graphics.BufferObject
    {
        /// <summary>
        /// Creates a new IndexBuffer from the given verticies
        /// </summary>
        /// <param name="indices">Array of indices to write to vram</param>
        public IndexBuffer(int[] indices) : base(OpenTK.Graphics.BufferTarget.ElementArrayBuffer)
        {
            Insert((indices.Length * sizeof(int)), indices);
        }       
    }

    /// <summary>
    /// A BufferObject containing Texture Coordinates for a VertexBuffer
    /// </summary>
    public class TexCoordBuffer : Rekx.Graphics.BufferObject
    { 
        /// <summary>
        /// Creates a new TexCoordBuffer from the give texcoords
        /// </summary>
        /// <param name="texCoords">TexCoords to write to vram</param>
        public TexCoordBuffer(Vector2[] texCoords) : base(OpenTK.Graphics.BufferTarget.ArrayBuffer)
        {
            Insert((texCoords.Length * Marshal.SizeOf(new Vector2())), texCoords);
        }
    }
}
